﻿using XmlStudio.Interfaces;

namespace XmlStudio.DataLayer {
    /// <summary>
    /// Represents xml attribute.
    /// </summary>
    internal class BigXmlAttribute : IBigXmlAttribute {
        /// <summary>
        /// Initializes a new instance of the <see cref="BigXmlAttribute"/> class.
        /// </summary>
        /// <param name="prefix">Attribute's prefix.</param>
        /// <param name="localName">Attribute's local name.</param>
        /// <param name="namespaceURI">Attribute's namespace uri.</param>
        /// <param name="value">Attribute's value.</param>
        public BigXmlAttribute(string prefix, string localName, string namespaceURI, string value) {
            this.Prefix = prefix;
            this.LocalName = localName;
            this.NamespaceURI = namespaceURI;
            this.Value = value;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="BigXmlAttribute"/> class.
        /// </summary>
        /// <param name="name">Attribute's name.</param>
        /// <param name="value">Attribute's value.</param>
        public BigXmlAttribute(string name, string value)
            : this(string.Empty, name, string.Empty, value) {
        }

        #region IBigXmlAttribute Members
        /// <summary>
        /// Gets the attribute's prefix.
        /// </summary>
        public string Prefix {
            get;
            private set;
        }

        /// <summary>
        /// Gets the attribute's local name.
        /// </summary>
        public string LocalName {
            get;
            private set;
        }

        /// <summary>
        /// Gets the attribute's namespace uri.
        /// </summary>
        public string NamespaceURI {
            get;
            private set;
        }

        /// <summary>
        /// Gets the attribute's value.
        /// </summary>
        public string Value {
            get;
            private set;
        }

        /// <summary>
        /// Gets the attribute's name.
        /// </summary>
        public string Name {
            get {
                return string.IsNullOrEmpty(Prefix) ? LocalName : string.Format("{0}:{1}", Prefix, LocalName);
            }
        }
        #endregion

        public static string CreateKey(string prefix, string localName, string namespaceURI) {
            return string.Format("{0}:{1}:{2}", prefix, localName, namespaceURI);
        }
    }
}